package com.umakr.ax.app.web;

import java.util.Date;
import java.util.Map;

import com.umakr.ax.app.service.PluginCouponWebService;
import com.umakr.ax.common.service.PluginCouponService;
import com.umakr.ax.common.service.SpreadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.ui.ModelMap;
import com.umakr.ax.common.model.PluginCoupon;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.umakr.ax.core.base.AbstractController;

/**
 * <p>
 * ${table.comment}  前端控制器
 * </p>
 *
 * @author Umakr-Code-Generator
 * @since 2017-12-30
 */
@Controller
@RequestMapping("/api/web/pluginCoupon")
public class PluginCouponWebController extends AbstractController {

	@Autowired
	PluginCouponWebService pluginCouponWebService;

	@ApiOperation(value = "软删除优惠券")
	@GetMapping("/delPluginCoupon")
	@ResponseBody
	public Object delPluginCoupon(ModelMap modelMap,@RequestParam(name = "id") Long id, @RequestParam(name = "delStatus") Integer delStatus) {
		return setSuccessModelMap(modelMap,pluginCouponWebService.delPluginCoupon(id,delStatus));
	}

	@ApiOperation(value = "优惠券列表")
	@GetMapping("/listPluginCoupon")
	@ResponseBody
	public Object listPluginCoupon(ModelMap modelMap,@RequestParam(name = "rsId") Long rsId) {
		return setSuccessModelMap(modelMap,pluginCouponWebService.listPluginCoupon(rsId));
	}

	@ApiOperation(value = "优惠券列表-加过滤条件")
	@GetMapping("/listPluginCouponByTitle")
	@ResponseBody
	public Object listPluginCouponByTitle(ModelMap modelMap,@RequestParam(name = "rsId") Long rsId,String title) {
		return setSuccessModelMap(modelMap,pluginCouponWebService.listPluginCouponByTitle(rsId,title));
	}

	@ApiOperation(value = "根据Id获取优惠券")
	@GetMapping("/getPluginCouponById")
	public Object getPluginCouponById(ModelMap modelMap,Long pcId) {
		return setSuccessModelMap(modelMap,pluginCouponWebService.getPluginCouponById(pcId));
	}

	@ApiOperation(value = "发布优惠券")
	@PostMapping("/savePluginCoupon")
	@ResponseBody
	public Object savePluginCoupon(ModelMap modelMap, PluginCoupon pluginCoupon) {
		logger.info("==========================开始时间："+pluginCoupon.getRpcStarttime()+"=========结束时间"+pluginCoupon.getRpcEndtime());
		return setSuccessModelMap(modelMap,pluginCouponWebService.savePluginCoupon(pluginCoupon));
	}
	/**
	 * @param modelMap
	 * @return
	 */
	@GetMapping("/makeTmp")
	@ApiOperation(value = "生成优惠券模板")
	public Object makeTmp(ModelMap modelMap, Long couponId) {
		return setSuccessModelMap(modelMap,pluginCouponWebService.makeTmp(couponId));
	}
}